home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 4490 / 4490.xpi / components / scripts / gmail.js < prev    next >
Text File  |  2010-01-25  |  4KB  |  116 lines

  1. /***********************************************************
  2. Gmail
  3. ***********************************************************/
  4. var hostString="gmail.com";
  5. var supportInboxOnly=true;
  6. var supportShowFolders=true;
  7.  
  8. function init(){
  9.   this.initStage=ST_PRE;
  10.  
  11.   var ar=this.user.split("@");
  12.   if(ar[1]=="gmail.com"||ar[1]=="googlemail.com"){
  13.     this.loginData=["https://www.google.com/accounts/ServiceLoginAuth?service=mail",
  14.                       "Email","Passwd",
  15.                       "continue=https%3A%2F%2Fmail.google.com%2Fmail%2F"];
  16.     this.dataURL="https://mail.google.com/mail";                      
  17.     this.mailURL="https://mail.google.com/mail";//used in below process!
  18.     this.mailDomain=".+?.google.com";    
  19.     if(this.getCookie("google.com","SID")!=null)this.loginData[3]+="&PersistentCookie=yes";
  20.   }else{//Google Apps
  21.     this.dataURL="https://mail.google.com/a/"+ar[1];
  22.     this.mailURL="https://mail.google.com/a/"+ar[1];//used in below process!
  23.     this.mailDomain=".+?.google.com";                          
  24.     this.loginData=["https://www.google.com/a/"+ar[1]+"/LoginAction2?service=mail",
  25.                       "","Passwd",
  26.                       "continue="+encodeURIComponent(this.mailURL)+"&service=mail&Email="+encodeURIComponent(ar[0])];
  27.   }  
  28. }
  29. function getIconURL(){
  30.   return "http://mail.google.com/favicon.ico";
  31. }
  32. function process(aHttpChannel, aData) {
  33.   switch(this.stage){
  34.   case ST_PRE:
  35.     this.getHtml(this.mailURL);
  36.     return false;
  37.   case ST_PRE_RES:
  38.     var fnd=aData.match(/GALX[\s\S]+?value=\"(\S+?)\"/);
  39.     if(fnd){
  40.       this.stage=ST_LOGIN;
  41.       this.getHtml(this.loginData[LOGIN_URL],this.loginData[LOGIN_POST]+"&GALX="+encodeURIComponent(fnd[1]));
  42.       return false;
  43.     }
  44.     this.onError();
  45.     return true;
  46.   case ST_LOGIN_RES:
  47.     var fnd=aData.match(/<meta.+?url=(?:'|')(\S+)(?:'|')/);
  48.     if(fnd){
  49.       fnd=fnd[1].replace(/&/g,"&");
  50.       this.getHtml(fnd);
  51.       return false;
  52.     }
  53.     ++this.stage;//Google Apps
  54.   case (ST_LOGIN_RES+1):
  55.     var fnd=aData.match(/GLOBALS=\[(?:(.*?),){10}/);
  56.     if(fnd){
  57.       fnd=fnd[1].replace(/\"/g,"");
  58.       this.dataURL=this.mailURL+"/?ui=2&ik="+fnd+"&view=tl&start=0&num=25&rt=h&as_has=is%3Aunread&as_subset="+(this.inboxOnly?"inbox":"all")+"&search=adv";
  59.       this.newUI=true;
  60.     }else{
  61.       this.dataURL=this.mailURL+"/?ui=1&view=tl&search=query&start=0&q=is%3Aunread"+(this.inboxOnly?"%20in%3Ainbox":"");
  62.       this.newUI=false;
  63.     }
  64.     this.stage=ST_DATA;
  65.     break;
  66.   }
  67.   return this.baseProcess(aHttpChannel, aData);
  68. }
  69. function getCount(aData){
  70.   var fnd;
  71.   if(this.newUI){
  72.     if(this.inboxOnly)fnd=aData.match(/"ld",\[\["\^i",(\d+)/);
  73.     else fnd=aData.match(/D\(\["ti",.+?,(\d+)/);
  74.   }else{
  75.     if(this.inboxOnly)fnd=aData.match(/"ds",\[\["inbox",(\d+)/);
  76.     else fnd=aData.match(/D\(\["ts",\d*,\d*,(\d+)/);
  77.   }  
  78.   if(fnd){
  79.     return fnd[1];
  80.   }else{
  81.     return -1;
  82.   }
  83. }
  84. function getDesc(){
  85.   var n=this.calcCount();
  86.   if(this.inboxOnly)return n>=0?n:"";
  87.   else return n>=100?"~"+n:(n>=0?n:"");
  88. }
  89. function getMailURL(aFolder){
  90.   if(aFolder){
  91.     if(this.newUI)return this.mailURL+"/#label/"+encodeURIComponent(aFolder);
  92.     else return this.mailURL+"/?s=l&l="+encodeURIComponent(aFolder);
  93.   }
  94.   return this.mailURL;  
  95. }
  96. function getData(aData){
  97.   var obj={};
  98.   if(!this.showFolders)return obj;
  99.   var fnd;
  100.   if(this.newUI)fnd=aData.match(/\["ld"\s*,\s*\[(?:,?\[.+?\]\n)+\]\n,\[((?:,?\[.+?\]\n)+)\]\n\]\n\)/);
  101.   else fnd=aData.match(/\["ct"\s*,\s*\[([\s\S]*?)\]\n\]\n\)/);
  102.   if(fnd){
  103.     var re=/\[\"(.+)\"\s*,\s*(\d+)/g;
  104.     var o;
  105.     var ar=[];
  106.     while ((o = re.exec(fnd[1])) != null){
  107.       if(parseInt(o[2])>0){
  108.         ar.push(o[1]);
  109.         ar.push(o[2]);
  110.       }
  111.     }
  112.     if(ar)obj.folders=encodeArray(ar);
  113.   }
  114.   return obj;
  115. }
  116.